<template>
    <view class=""></view>
</template>

<script lang="ts" setup>
import { onShow } from "@dcloudio/uni-app"
import { nextTick, ref } from "vue";

const ws = ref()
const socketOpen = ref<boolean>(false)

onShow(() => {
    uni.connectSocket({
        url: 'ws://127.0.0.1:7272',
        // success: () => {
        //     console.log('连接成功');
        //     socketOpen.value = true
        // },
        // fail: (err) => {
        //     console.error('连接失败', err);
        // },
        complete: ()=> {}
    })

    uni.onSocketOpen((res: any) => {
        socketOpen.value = true
        console.log('WebSocket连接已打开！', res)
    })

    uni.onSocketMessage((res: any) => {
        console.log('收到服务器内容：' + res.data);
    })

    uni.onSocketError((res: any) => {
        console.log('WebSocket连接打开失败，请检查！', res);
    })

    uni.onSocketClose((res: any) =>  {
        console.log('WebSocket 已关闭！');
    })
})
</script>

<style scoped lang="scss">

</style>